package hu.test.atacama;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcel;
import android.os.Parcelable;

public class DataFromDevice implements Parcelable {

	private String deviceType;

	private String senderID;

	private String serialNumber;

	private String command;

	private String metaData;

	public List<String> gpsData = new ArrayList<String>();

	private List<Long> recordedAt = new ArrayList<Long>();

	public DataFromDevice(String deviceType, String senderID,
			String serialNumber, String gpsData, Long timeStamp, String command) {
		this.deviceType = deviceType;
		this.senderID = senderID;
		this.serialNumber = serialNumber;
		this.command = command;
		this.metaData = "None";
		this.gpsData.add(gpsData);
		this.recordedAt.add(timeStamp);
	}

	public DataFromDevice(String deviceType, String senderID,
			String serialNumber, String gpsData, Long timeStamp,
			String command, String metaData) {
		this.deviceType = deviceType;
		this.senderID = senderID;
		this.serialNumber = serialNumber;
		this.command = command;
		this.metaData = metaData;
		this.gpsData.add(gpsData);
		this.recordedAt.add(timeStamp);
	}

	protected DataFromDevice(Parcel in) {
		deviceType = in.readString();
		senderID = in.readString();
		serialNumber = in.readString();
		command = in.readString();
		metaData = in.readString();
		gpsData = new ArrayList<String>();
		in.readList(gpsData, null);
		recordedAt = new ArrayList<Long>();
		in.readList(recordedAt, null);
	}

	public int describeContents() {
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(deviceType);
		dest.writeString(senderID);
		dest.writeString(serialNumber);
		dest.writeString(command);
		dest.writeString(metaData);
		dest.writeList(gpsData);
		dest.writeList(recordedAt);
	}

	public static final Parcelable.Creator<DataFromDevice> CREATOR = new Parcelable.Creator<DataFromDevice>() {
		public DataFromDevice createFromParcel(Parcel in) {
			return new DataFromDevice(in);
		}

		public DataFromDevice[] newArray(int size) {
			return new DataFromDevice[size];
		}
	};
	
	public void addCoordinate(Coordinates coordinates) {
		this.gpsData.add(coordinates.getLatitude() + "," + coordinates.getLongitude());
		this.recordedAt.add(Long.parseLong(coordinates.getTime()));
	}
}